package l1j.server.server.clientpackets;

import l1j.opqlo.Server.L1World.L1World;
import l1j.server.echo.ClientThread;
import l1j.server.server.model.L1Object;
import l1j.server.server.model.Instance.L1PcInstance;
import l1j.server.server.model.Instance.L1PetInstance;
import l1j.server.server.serverpackets.S_PetInventory;

import java.util.logging.Level;
import java.util.logging.Logger;
/**
 * 處理收到由客戶端傳來寵物選單的封包
 */
public class C_PetMenu extends ClientBasePacket {
	private static final Logger _log = Logger.getLogger(C_PetMenu.class.getName());
	private static final String C_PET_MENU = "[C] C_PetMenu";
	@Override
	public String getType() {
		return C_PET_MENU;
	}

	@Override
	public void start(final byte[] decrypt, final ClientThread client) {
		try {
			// 資料載入
			this.read(decrypt);
		final L1PcInstance pc = client.getActiveChar();
		if (pc == null) {
			return;
		}

		final int petId = this.readD();
		final L1Object obj =  L1World.getInstance().findObject(petId);
		if(obj instanceof L1PetInstance){
		final L1PetInstance pet = (L1PetInstance) obj;
		if (pet != null ) {
			pc.sendPackets(new S_PetInventory(pet));
		}
		}
	} catch (final Exception e) {
		_log.log(Level.SEVERE, e.getLocalizedMessage(), e);

	} finally {
		this.over();
	}
	}
}
